
/**
 * 
 * @param {*} timestamp 时间格式的字符串或时间戳，能被 Date()转换
 * @returns year-month-day h:m:s
 */
const timestampToTime = (timestamp) => {
    // console.log(timestamp)
    if (!timestamp) 
    return '空'
    let date = new Date(timestamp) //时间戳为10位需*1000，时间戳为13位的话不需乘1000
    let Y = date.getFullYear() 
    let M =
        (date.getMonth() + 1 < 10 ?
            '0' + (date.getMonth() + 1) :
            date.getMonth() + 1)
    let D =
        (date.getDate() < 10 ? '0' + date.getDate() : date.getDate())
    let h =
        (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) 
    let m =
        (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) 
        
    let s =
        date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()
        if(h=='00' && m=='00' && s=='00')
        {
            if(D=='00')
            {
                return  Y + '-'+ M
            }
            else
            {
                return  Y + '-'+ M  + '-'+ D
            }
            
        }
        else
        {
            return Y+ '-' + M  + '-'+ D + ' ' + h +':'+ m+':' + s
        }
    
};

/**
 * 
 * @param {*} timestamp 时间格式的字符串或时间戳，能被 Date()转换
 * @returns year-month-day
 */
const timeToDate = (value) => {
   if (!value) return ''
    // console.log(value.getFullYear())
    value = new Date(value)   //先默认转换为日期对象
    let [year,month,day]=[value.getFullYear(),value.getMonth()+1,value.getDate()]
    // console.log(year,month,day)
    // return value.charAt(0).toUpperCase() + value.slice(1)
    return year+'-'+month+'-'+day;
};



/**
 * 导出 
 **/
export {
    timestampToTime,
    timeToDate
   
}